<template>
	<view class="page flex-col">
			<cu-custom bgColor="bg-gradual-pink" :isBack="true">
				<block slot="backText">返回</block>
				<block slot="content">用户详情</block>
				<!-- <view slot="right" @tap="rightClick">编辑</view> -->
			</cu-custom>
			<!-- list列表 -->
			<view class="cu-list menu">
				<view class="cu-item animation-slide-bottom" :style="[{animationDelay: '0.1s'}]">
					<view class="content">
						<text class="text-grey">头像</text>
					</view>
					<view class="action">
						<view class="cu-avatar round sm" :style="{backgroundImage: 'url(' + $getFileAccessHttpUrl(personalMsg.avatar) + ')'}">
						</view>
					</view>

				</view>
				<view class="cu-item animation-slide-bottom" :style="[{animationDelay: '0.1s'}]">
					<view class="content">
						<text class="text-grey">账号</text>
					</view>
					<view class="action">
						<text class="text-grey">{{personalMsg.account}}</text>
					</view>
				</view>
				<view class="cu-item animation-slide-bottom" :style="[{animationDelay: '0.2s'}]">
					<view class="content">
						<text class="text-grey">用户名</text>
					</view>
					<view class="action">
						<text class="text-grey">{{personalMsg.userName}}</text>
					</view>
				</view>
				<view class="cu-item animation-slide-bottom" :style="[{animationDelay: '0.2s'}]">
					<view class="content">
						<text class="text-grey">用户类型</text>
					</view>
					<view class="action">
						<text class="text-grey">{{personalMsg.userType == 1 ? '公司' : '个人'}}</text>
					</view>
				</view>
				<view class="cu-item animation-slide-bottom" :style="[{animationDelay: '0.3s'}]">
					<view class="content">
						<text class="text-grey">手机号</text>
					</view>
					<view class="action">
						<text class="text-grey">{{personalMsg.phone}}</text>
					</view>
				</view>
				<view class="cu-item animation-slide-bottom" :style="[{animationDelay: '0.4s'}]">
					<view class="content">
						<text class="text-grey">电话号码</text>
					</view>
					<view class="action">
						<text class="text-grey">{{personalMsg.telephone}}</text>
					</view>
				</view>
				<view class="cu-item animation-slide-bottom" :style="[{animationDelay: '0.5s'}]">
					<view class="content">
						<text class="text-grey">邮箱</text>
					</view>
					<view class="action">
						<text class="text-grey">{{personalMsg.email}}</text>
					</view>
				</view>
				<block v-if="personalMsg.userType == 1">
					<view class="cu-item animation-slide-bottom" :style="[{animationDelay: '0.6s'}]">
						<view class="content">
							<text class="text-grey">公司名称</text>
						</view>
						<view class="action">
							<text class="text-grey">{{personalMsg.company}}</text>
						</view>
					</view>
					
					<view class="cu-item animation-slide-bottom" :style="[{animationDelay: '0.7s'}]">
						<view class="content">
							<text class="text-grey">税号</text>
						</view>
						<view class="action">
							<text class="text-grey">{{personalMsg.taxNo}}</text>
						</view>
					</view>
					<view class="cu-item animation-slide-bottom" :style="[{animationDelay: '0.8s'}]">
						<view class="content">
							<text class="text-grey">发票抬头</text>
						</view>
						<view class="action">
							<text class="text-grey">{{personalMsg.titleName}}</text>
						</view>
					</view>
				</block>
				
				<view class="cu-item animation-slide-bottom" :style="[{animationDelay: '0.9s'}]">
					<view class="content">
						<text class="text-grey">备注</text>
					</view>
					<view class="action">
						<text class="text-grey">{{personalMsg.remark}}</text>
					</view>
				</view>
			</view>
			<view class="padding flex flex-direction tong-fixed">
				<button type="warn" class="cu-btn bg-red lg" @click="rightClick">编辑</button>
			</view>
	</view>
</template>

<script>
	import api from '@/api/api.js'
	import {
		USER_INFO
	} from "@/common/util/constants"
	import server from '@/api/server.js'
	import { encryption,decryption } from '@/common/util/aesEncrypt'
	import desensitizedUtils from '@/common/util/desensitized'
	export default {
		data() {
			return {
				personalMsg: {
					avatar: '',
					realname: '',
					username: '',
					sex: 1,
					birthday: new Date(),
					orgCode: '',
					workNo: '',
					status: 1,
					phone: '',
					telephone: '',
					email: '',
					post: '',
					departIds: '',
					identity: '',
				},
				personalList:{},
				userUrl: '/sys/user/queryById',
				positionUrl: '/sys/position/list',
				departUrl: '/sys/user/userDepartList'
			};
		},
		onShow() {
			this.loadinfo()
		},
		methods: {
			getSubStringText(text, len) {
				if (!text || text.length == 0) {
					return ''
				}
				if (text.length < len) {
					return text;
				}
				return text.substr(0, len) + "..."
			},
			rightClick() {
				// this.$Router.push({
				// 	name: 'useredit',
				// 	params: this.personalMsg
				// })
				uni.navigateTo({
				    url: '/pages/user/useredit'
				});
			},
			loadinfo() {
				let result = uni.getStorageSync(USER_INFO)
				console.log("用户", uni.getStorageSync(USER_INFO))
				server.getEncryptedString().then(res => {
					var phone = decryption(result.phone,res.data.result.key,res.data.result.iv)
					this.personalMsg.phone = desensitizedUtils.desensitizedPhone(phone)
					var email = decryption(result.email,res.data.result.key,res.data.result.iv)
					this.personalMsg.email = desensitizedUtils.desensitizedEmail(email)
					
				})

				this.personalMsg.avatar = result.avatar
				this.personalMsg.account = result.account
				this.personalMsg.userName = result.userName
				this.personalMsg.userType = result.userType
				this.personalMsg.telephone = result.telephone == null ? '' : result.telephone
				this.personalMsg.company = result.company
				this.personalMsg.taxNo = result.taxNo == null ? '' : result.taxNo
				this.personalMsg.titleName = result.titleName == null ? '' : result.titleName
				this.personalMsg.remark = result.remark == null ? '' : result.remark
				this.$forceUpdate()
				
			},
		}
	}
</script>

<style>
	.page {
		height: 100Vh;
		width: 100vw;
	}

	.switch-sex::after {
		content: "\e716";
	}

	.switch-sex::before {
		content: "\e7a9";
	}

	.switch-music::after {
		content: "\e66a";
	}

	.switch-music::before {
		content: "\e6db";
	}
	.cu-list.menu{
		padding-bottom: 100px;
	}
</style>
